package xgenerator.ui.swing;

import javax.swing.*;
import java.awt.*;

/**
 * <p>
 * Title：
 * </p>
 * <p>
 * Description：http://hi.baidu.com/guoweihome/blog/item/ddeffaf8fa205a0ad8f9fd79.html
 * </p>
 * <p>
 * Copyright: Copyright (c) 2012
 * </p>
 * <p>
 * Company: liss
 * </p>
 * 
 * @author <a href="mailto:shushanlee@msn.com">liss</a>
 * @version 1.0
 * @see
 * @since 1.0
 */
public class SplashScreen extends JFrame {

	/**
	 * @param args
	 *            制作快闪屏
	 */
	private JFrame splashScreen = null;

	public SplashScreen() {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				showScreen();
			}
		});
		// 初始化工作
		try {
			Thread.sleep(3000);
		} catch (Exception e) {
			System.out.println("系统休眠错误");
		}

		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				hideScreen();
			}
		});

	}

	public void showScreen() {
		ImageIcon image = null;
		try {
			image = new ImageIcon("Image\\splash.jpg");
		} catch (Exception e) {
			System.out.println("File not found!");
		}
		// 图片大小
		int width = image.getImage().getWidth(null);
		int height = image.getImage().getHeight(null);

		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

		JLabel label = new JLabel(image);
		this.splashScreen = new JFrame();

		this.splashScreen.setSize(width, height);
		this.splashScreen.setLocation(((int) d.width - width) / 2, ((int) d.height - height) / 2);

		this.splashScreen.getContentPane().add(label);

		this.splashScreen.setUndecorated(true);

		this.splashScreen.setVisible(true);

	}

	public void hideScreen() {
		this.splashScreen.setVisible(false);
		this.splashScreen = null;
	}

	public static void main(String[] args) {
		SplashScreen ma = new SplashScreen();
	}

}